<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">
        	<a onclick='onAdd()' class='btn btn-primary'>添加等级</a>
            <div class="card">
                <div class="card-body">
                    <table id="table"></table>
                </div>
            </div>
        </div>
    </div>
</div> 

<style>
.control-label {
    padding-top: 7px;
}
</style>

<script>
var columns = [{
    field: 'title',
    title: '等级名称'
}, {
    field: 'uprice',
    title: '升级年费'
}, {
    field: 'bprice',
    title: '升级返佣'
}, {
    field: 'operate',
    title: '操作',
    formatter: function(value,item){ // 自定义方法
        let html = '';
        html += '<div class="btn-group">';
            html += '<a class="btn btn-xs btn-default edit-btn" data-toggle="tooltip" title="编辑"><i class="mdi mdi-pencil"></i></a>';
        html += '</div>';
        return html;
    }, 
    events: {
        'click .edit-btn': function (event, value, row, index) {
            event.stopPropagation();
            onAdd(row)
        },
    }
}];
$('#table').bootstrapTable({
    url: '/SPAdmin/level',
    dataType: 'json',
	method: 'post',
    pagination: true,//开启分页
    pageSize:15,
    pageNumber:1,
    sidePagination:'server',
    search: false, //开启刷选
    columns: columns,
    queryParams:function(params) {
        /******获取分页数据时，这里你可以带上你自定义的参数,bootstrap table会把这些参数合并到请求里******/
       return params;
	}
});

function onAdd(item){
	var str = "";
	str += '<div class="input-group" style="margin-bottom: 10px;">'
	str += '<div class="input-group-text">等级名称</div>'
	str += '<input type="text" maxlength="6" class="form-control" value="'+(item ? item.title : '')+'">'
	str += '</div>'
	str += '<div class="input-group" style="margin-bottom: 10px;">'
	str += '<div class="input-group-text">升级年费</div>'
	str += '<input type="number" class="form-control" value="'+(item ? item.uprice : '')+'">'
	str += '</div>'
	str += '<div class="input-group" style="margin-bottom: 10px;">'
	str += '<div class="input-group-text">升级返佣</div>'
	str += '<input type="text" class="form-control" value="'+(item ? item.bprice : '')+'">'
	str += '</div>'
	str += '<div class="input-group">'
	str += '<div class="input-group-text">等级说明</div>'
	str += '<textarea class="form-control">'+(item ? item.rule : '')+'</textarea>'
	str += '</div>'
	$.confirm({
		title:'等级信息',
		content: str,
        buttons:{
        	confirm:{ 
        		text:'确认',
        		btnClass: "btn-primary",
        		action: function(){
            		var input = this.$content.find('input');
            		var data = {title:$(input[0]).val(),uprice:$(input[1]).val(),bprice:$(input[2]).val(),rule:this.$content.find('textarea').val()};
            		if(data.title == '') return $.notify('名称不能为空');
					if(item) data['lid'] = item.id;
        			showLoading();
	                $.ajax({
	                	url:"/SPAdmin/level/post",
	                	type:'post',
	                	dataType:'json',
	                	data:data,
	                	success:function(res){
	                		hideLoading();
	                		if(res.code == 1){
	                			$.notify('操作成功');
                                $('#table').bootstrapTable('refresh')
	                		}else $.notify(res.msg);
	                	}
	                });
	            },
        	},
        	cancel:{text:'取消'}
        }
	});
}

</script>
